﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class user_favimg_add : System.Web.UI.Page
{
    a_AlbumCollection albums;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!SessionManager.IsLogged)
            Response.Redirect("login.aspx?ckid=" + SessionManager.GetCookie(), true);
        albums = a_AlbumService.Geta_AlbumListBySSID(SessionManager.GetCookie(), a_AlbumColumns.Name, ThoiTrang.Data.OrderDirection.ASC);
        
        if (albums != null)
        {
            foreach (a_Album ab in albums.ToArray())
            {
                lstAlbum.Items.Add(new ListItem(ab.Name, ab.ID.ToString()));
            }
        }
        //lstAlbum.Attributes.Add("name", "albumId");
        lstAlbum.Attributes.Add("class", "album");
        AlbumType.Attributes.Add("class", "loaialbum");
        if (IsPostBack)
        {
            text.InnerHtml = lstAlbum.Items[lstAlbum.SelectedIndex].Value + tenalbum.Value + AlbumType.Items[AlbumType.SelectedIndex].Value + Request["act"];
            //switch (Request["act"])
            //{
            //    case "SaveAlbum":
            //        break;
            //    case "CreateAlbum":

            //        break;
            //    default: break;
            //}
            int idAlbum = 0;
            if (Request["act"] == "CreateAlbum")
            {
                if (tenalbum.Value == string.Empty)
                    text.InnerHtml = "Chưa nhập tên album!";
                else
                {
                    a_User usr = a_UserService.Geta_UserBySSID(SessionManager.GetCookie());
                    a_Album ab = new a_Album();
                    ab.Name = tenalbum.Value;
                    ab.StatPopularity = 0;
                    ab.AlbumType = bool.Parse(AlbumType.Items[AlbumType.SelectedIndex].Value);
                    ab.UserID = usr.UserID;
                    a_AlbumService.Createa_Album(ab);
                    idAlbum = ab.ID;
                }
            }
            else
                idAlbum = int.Parse(lstAlbum.Items[lstAlbum.SelectedIndex].Value);
            if (idAlbum != 0)
            {
                a_Favorite fav = new a_Favorite();
                fav.AlbumID = idAlbum;
                fav.FavoriteID = int.Parse(Request["fid"]);
                fav.FavoriteType = byte.Parse(Request["dt"]);
                a_FavoriteService.Createa_Favorite(fav);
                Response.Redirect("detail.aspx?aid=" + Request["aid"] + "&ckid=" + SessionManager.GetCookie() + "&msg=2", true);
            }
            else
                text.InnerHtml = "Có lỗi xảy ra!";
        }
    }
}
